int8 i2c_test_rw_byte (int8 adr)
{
#define MAX_COUNT   (0x1F0) 
    int16   i;
    int8    buff    [MAX_COUNT];
    int8    buff_1  [MAX_COUNT];
    int8    sts = 0;
    
    printf ("TESTING I2C MEM ");

    for ( i=0; i<MAX_COUNT; i++) {
        buff_1[i] = rand();
        if (write_i2c_dev(adr, i, &buff_1[i])) {
            printf ("Write err i2c...\r\n");
            break;
        }
        
        if (read_i2c_dev(adr, i, &buff[i])) {
            printf ("Read err i2c...\r\n");
            break;
        }
        //printf(".");
    }

    for(i = 0; i < MAX_COUNT; i++) {
        if (buff_1[i] != buff[i]) {
            printf("ERROR Adr 0x%X Val w 0x%X Val r 0x%X\r\n",
                i, buff_1[i], buff[i]);
            sts = 1;
            break;
        }
    }
    return sts;
}

int8 i2c_test_rw_block (int8 adr)
{
#define MAX_COUNT   (0x1F)   
    int16   i;
    int8    buff    [MAX_COUNT];
    int8    buff_1  [MAX_COUNT];
    int8    sts = 0;
    
    printf ("TESTING I2C MEM BLOCK ...\r\n");

    for ( i=0; i<MAX_COUNT; i++) {
        buff_1[i] = rand();
    }

    if (write_i2c_dev_block(adr, 0, &buff_1[0], MAX_COUNT)) {
        printf ("Write err i2c...\r\n");
        break;
    }
#if 0
    if (read_i2c_dev_block(adr, 0, &buff[0], MAX_COUNT)) {
        printf ("Read err i2c...\r\n");
        break;
    }
#endif
    for ( i=0; i<MAX_COUNT; i++) {
        if (read_i2c_dev(adr, i, &buff[i])) {
            printf ("Read err i2c...\r\n");
            break;
        }
        printf(".");
    }

    for(i = 0; i < MAX_COUNT; i++) {
        if (buff_1[i] != buff[i]) {
            printf("ERROR Adr 0x%X Val w 0x%X Val r 0x%X\r\n",
                i, buff_1[i], buff[i]);
            sts = 1;
            break;
        }
    }

    return sts;
}

